using InfoTech.VinhSon.Bussiness;
using InfoTech.VinhSon.IRepository;
using InfoTech.VinhSon.Repository;

namespace VinhSon.Models
{
    public class UnitOfWork
    {

        #region Context

        protected readonly VinhSonContext Context = new VinhSonContext();

        public void Save()
        {
            Context.SaveChanges();
        }

        #endregion

        #region Repository fields

        private IUserRepository _UserRepository;

        private IArticleRepository _ArticleRepository;

        private ICategoryRepository _CategoryRepository;

        private ISectionRepository _SectionRepository;

        private IConfigRepository _ConfigRepository;

        private ICSectionRepository _CSectionRepository;

        private IGroupRepository _GroupRepository;

        private ILayoutRepository _LayoutRepository;

        private IArticleGroupRepository _articleGroupRepository;

        #endregion

        #region Repository properties

        public IUserRepository UserRepository
        {
            get
            {
                return _UserRepository ?? (_UserRepository = new UserRepository(Context));
            }
        }

        public IArticleRepository ArticleRepository
        {
            get
            {
                return _ArticleRepository ?? (_ArticleRepository = new ArticleRepository(Context));
            }
        }

        public ICategoryRepository CategoryRepository
        {
            get
            {
                return _CategoryRepository ?? (_CategoryRepository = new CategoryRepository(Context));
            }
        }

        public ISectionRepository SectionRepository
        {
            get
            {
                return _SectionRepository ?? (_SectionRepository = new SectionRepository(Context));
            }
        }

        public IConfigRepository ConfigRepository
        {
            get
            {
                return _ConfigRepository ?? (_ConfigRepository = new ConfigRepository(Context));
            }
        }

        public ICSectionRepository CSectionRepository
        {
            get
            {
                return _CSectionRepository ?? (_CSectionRepository = new CSectionRepository(Context));
            }
        }

        public ILayoutRepository LayoutRepository
        {
            get
            {
                return _LayoutRepository ?? (_LayoutRepository = new LayoutRepository(Context));
            }
        }

        public IGroupRepository GroupRepository
        {
            get
            {
                return _GroupRepository ?? (_GroupRepository = new GroupRepository(Context));
            }
        }

        public IArticleGroupRepository ArticleGroupRepository
        {
            get
            {
                return _articleGroupRepository ?? (_articleGroupRepository = new ArticleGroupRepository(Context));
            }
        }

        #endregion
    }
}
